package com.example.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.example.common.Result;
import com.example.common.enums.ResultCodeEnum;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.entity.Animal;
import com.example.entity.Notice;
import com.example.service.AnimalService;
import com.example.service.NoticeService;
import com.example.service.UserService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/wx")
@Api(tags = "小程序相关接口")
public class WeiXinController {

    @Resource
    private AnimalService animalService;

    @Resource
    private UserService userService;


    @ApiOperation("查询全部宠物")
    @GetMapping("/animal/selectAll")
    public Result selectAll(Animal animal ) {
        List<Animal> list = animalService.selectAll(animal);
        return Result.success(list);
    }

    @ApiOperation("微信登录")
    @PostMapping("/login")
    public Result login(@RequestBody Account account) {
        if (ObjectUtil.isEmpty(account.getUsername()) || ObjectUtil.isEmpty(account.getPassword())) {
            return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
        }

        account = userService.login(account);
        return Result.success(account);
    }

    @ApiOperation("微信注册")
    @PostMapping("/register")
    public Result register(@RequestBody Account account) {
        if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getPassword())) {
            return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
        }
        userService.register(account);
        return Result.success();
    }



}